package org.example.service.imp;

import org.example.dao.imp.ActivityDaoImp;
import org.example.dao.imp.CourseDaoImp;
import org.example.entitys.managers.Course;
import org.example.entitys.relationship.Unit;
import org.example.entitys.relationship.student_unit_learning;
import org.example.entitys.relationship.teaching_evaluation;
import org.example.service.inter.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description 课程和学习单元的Service类
 * @Author 魏锴
 * @Date 2023/11/16
 */

@Service
public class CourseServiceImp implements CourseService {
    @Autowired
    public CourseDaoImp courseDaoImp;
    @Autowired
    public ActivityDaoImp activityDaoImp;

    @Override
    public boolean createCourse(Course course) {
        if (!activityDaoImp.isExitById(course.getActivity_id())) return false;
        return courseDaoImp.insertCourse(course) == 1;
    }

    @Override
    public boolean createLearnUnit(Unit unit) {
        return courseDaoImp.insertLearnUnit(unit) == 1;
    }

    @Override
    public boolean createEvaluation(teaching_evaluation evaluation) {
        return courseDaoImp.insertEvaluation(evaluation) == 1;
    }

    @Override
    public Unit findUnitById(int unit_id) {
        if (!courseDaoImp.isExitLearnUnitById(unit_id)) return null;
        return courseDaoImp.queryUnitById(unit_id);
    }

    @Override
    public student_unit_learning[] getHomeWorkByUnit(int unit_id) {
        return courseDaoImp.queryUnitRecordByUnit(unit_id).toArray(new student_unit_learning[0]);
    }

    @Override
    public student_unit_learning[] getHomeworkBySCI(int stu_in_class_id) {
        return courseDaoImp.queryUnitRecordBySCI(stu_in_class_id).toArray(new student_unit_learning[0]);
    }

}
